def a(x):
    if x == 1:
        return False
    test = True
    b = x - 1
    while b > 1:
        if not x % b:
            test = False
            break
        b -= 1
    return test
c = input()
otv = []
for i in range(len(c)):
    for g in range(i + 1, len(c) + 1):
        x = int(c[i:g])
        if a(x):
            otv += [x]
print(max(otv) if otv else 0)

